/***
 * 获取当前时间,并转换为 struct timespec
 * 即: timeval到timespec的手动转换
 * P333-334
 */

#include <sys/time.h>
#include <stdlib.h>

void maketimeout(struct timespec *tsp, long minutes)
{
    struct timeval now;

    /* get the current time */
    gettimeofday(&now, NULL);

    tsp->tv_sec = now.tv_sec;
    tsp->tv_nsec = now.tv_usec; /* use to nsec */

    /* add the offset to get timeout value */
    tsp->tv_sec += minutes * 60;
}